/*
 * BuilderMotionController.cpp
 *
 *  Created on: Jul 1, 2010
 *      Author: Ry
 */

#include "BuilderMotionController.h"



BuilderMotionController::BuilderMotionController(Object *player): PlayerMotionController(player) {
}

void BuilderMotionController::handleMovement(float dts) {
	btTransform t = player->getTransform();
	btQuaternion r = t.getRotation();

	// Next, compute the player's new position
	btVector3 v(0, 0, 0);
	btVector3 p = t.getOrigin();

	btMatrix3x3 m(r.inverse()); // Create matrix from current rotation
	btVector3 forward = m.getRow(2); // +Z axis
	btVector3 left = m.getRow(0);    // +X axis
	btVector3 backward = -forward;   // -Z axis
	btVector3 right = -left;         // -X axis

	if (moveForward) {
		v = v + forward;
	}
	if (moveBackward) {
		v = v + backward;
	}
	if (strafeLeft) {
		v = v + left;
	}
	if (strafeRight) {
		v = v + right;
	}

	if (v.length() > 0) {
		v.normalize();
	}

	v = v * maxVelocity;
	t.setOrigin(p + (v * dts));
	player->setTransform(t);
}

BuilderMotionController::~BuilderMotionController() {
}
